package com.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.pojo.ProductOrder;
import com.service.ProductOrderService;
import com.vo.ProductOrderVo;
import com.vo.R;
import com.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@CrossOrigin //开放前端的跨域访问
@Api(tags = "商品管理")
@RestController
@RequestMapping("/api/product")
public class ProductOrderController {

    @Resource
    private ProductOrderService productOrderService;

    @ApiOperation("测试接口")
    @GetMapping("/test")
    public R test(){

        return R.ok().data("message", "hello").data("now", new Date());
    }

    @ApiOperation("商品列表")
    @GetMapping("/list/{username}")
    public R list(@PathVariable String username){
        List<ProductOrder> list = productOrderService.findAll(username);
        System.out.println("订单列表为:" + list);
        return R.ok().data("productList", list);
    }

    @PostMapping("/addProductOrder")
    public R addProductOrder(@RequestBody ProductOrder productOrder){
//        System.out.println("获取的商品订单为" + productOrder);
        productOrderService.addProductOrder(productOrder);
        return R.ok();
    }

}
